package org.nicocube.airain.admin.server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nicocube.airain.domain.client.exception.DomainException;
import org.nicocube.airain.domain.server.dao.DomainDAO;
import org.nicocube.airain.domain.server.storable.GameDateManagerDAO;

public class TimeIncrementServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private GameDateManagerDAO gameDateManagerDAO;

	public TimeIncrementServlet() {
		gameDateManagerDAO = DomainDAO.getDao(GameDateManagerDAO.class);
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException, IOException {
		//super.doGet(req, resp);
		//if (! resp.isCommitted()) {
		try {
			gameDateManagerDAO.incCurrentSingleton();
			PrintWriter writer = resp.getWriter();
			writer.append("incremented !").flush();
			writer.close();
		} catch (DomainException e) {
			throw new ServletException("problem while trying to update GameDateManager current time",e);
		}
		//}
	}
}
